package com.zzyl.nursing.controller.member;

import com.github.pagehelper.PageInfo;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.dto.ElderlyInfoDto;
import com.zzyl.nursing.vo.*;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;


    /**
     * 登录
     * @param dto
     * @return
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }

    /**
     * 绑定老人
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ElderlyInfoDto dto){
        familyMemberService.add(dto);
        return success();
    }

    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam Long id){
        familyMemberService.deleteFamilyElderMemberById(id);
        return success();
    }

    /**
     * 获取当前登录用户的所有家属和老人信息
     * @return
     */
    @GetMapping("/my")
    public AjaxResult getMyFamilyElder(){
        List<FamilyMemberElderVo> myFamilyElder = familyMemberService.getMyFamilyElder();
        return success(myFamilyElder);
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list-by-page")
    public AjaxResult listByPage(Integer pageNum, Integer pageSize){
        PageInfo<FamilyMemberElderRelationVO> pageInfo =
                familyMemberService.listByPage(pageNum, pageSize);
        List<FamilyMemberElderRelationVO> list = pageInfo.getList();
        return success(list);
    }


    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable String iotId){
        List<DeviceDataVo> deviceDataVos = familyMemberService.queryServiceProperties(iotId);
        return success(deviceDataVos);
    }

    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(String iotId, String functionId, Long startTime, Long endTime){
        List<TimeSeriesDataVO> timeSeriesDataVOS = familyMemberService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return success(timeSeriesDataVOS);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(String iotId, String functionId, Long startTime, Long endTime){
        List<TimeSeriesDataVO> timeSeriesDataVOS = familyMemberService.queryWeeklyHeartRateData(iotId, functionId , startTime, endTime);
        return success(timeSeriesDataVOS);
    }

}
